﻿using System;
using RenrenApi;

namespace Web
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Request["code"] != null)
            //{
            //    string uid = Request["xn_sig_user"], sessionKey = Request["xn_sig_session_key"];
            //    Session["client"] = new RenrenApiClient(uid, sessionKey);
            //    Response.Write(Request["code"] + "<br />" + uid + "<br />" + sessionKey + "<br />"  + (Session["client"] != null));
            //    Response.Redirect("home.aspx");
            //}
            //else
            //{
            //    return;
            //    Response.Write(string.Format("<script type=\"text/javascript\">top.location.href=\"{0}\";</script>", RenrenApiConfig.RenrenGetAuthCodeUri));
            //}
            if (Request["xn_sig_user"] == null) // 未授权
            {
                var url = RenrenApiConfig.RenrenRedirectUri + Request.RawUrl;
                Response.Write(string.Format("<script type=\"text/javascript\">top.location.href=\"{0}\";</script>",
                                             RenrenApiConfig.RenrenGetAuthCodeUri(url)));
            }
            else
            {
                string uid = Request["xn_sig_user"], sessionKey = Request["xn_sig_session_key"];
                Session["client"] = new RenrenApiClient(uid, sessionKey);
                Response.Redirect(Request["redirect"] ?? "home.aspx");
            }
        }
    }
}